﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SpecF;

namespace SpecF.Samples
{
	class Customer
	{
		public int Money { get; set; }
		public int ShoppingCartCount { get; set; }
		public string Name { get; set; }
		public bool HasCouponCode { get; set; }

		public void Buy(string product, bool useCouponCode)
		{
			string couponUseText = useCouponCode ? "Used coupon code" : "Not used coupon code";
			Console.WriteLine("Customer buying product by name : {0}. {1}", product, couponUseText);
			++ShoppingCartCount;
		}

		public bool HasEnoughMoney() { return Money > 100; }
	}

	class Program
	{
		static void Main(string[] args)
		{
			Customer customerEntity = new Customer();
			customerEntity.Name = "John";
			customerEntity.Money = 200;
			customerEntity.HasCouponCode = true;

			SpecF<Customer>
				.When(customer => customer.HasEnoughMoney())
				.Then(customer =>
					{
						Console.WriteLine("Customer has enough money for shopping");
					})
				.Next(customer => customer.Name.Equals("John") && customer.HasEnoughMoney() && customer.HasCouponCode)
				.Then(customer =>
					{
						customer.Buy("Product B", true);
					})
				.Next(customer => customer.Name.Equals("John") && customer.HasEnoughMoney() && !customer.HasCouponCode)
				.Then(customer =>
					{
						customer.Buy("Product A", false);
					})
				.Next(customer => customer.ShoppingCartCount > 0)
				.Then(customer =>
					{
						Console.WriteLine("Customer has an item in shopping cart");
					})
			.ExecWithoutReport(customerEntity);

			Console.ReadLine();
		}
	}
}